package main

import (
	"io"
	"log"
	"net"
)

var a1 net.Conn

func HandlePortConn(c net.Conn) {
	log.Println("req", c.RemoteAddr())
	io.Copy(a1, c)
	log.Println("exit==========")
	a1.Close()
	c.Close()
}

func RunPortServer(strAddr string) {
	log.Println("Listen Port Server", strAddr)
	sListen, err := net.Listen("tcp", strAddr)
	if err != nil {
		log.Println("Listen", strAddr, "Error:", err.Error())
		return
	}
	defer sListen.Close()

	for {
		cConn, err := sListen.Accept()
		if err != nil {
			continue
		}
		go HandlePortConn(cConn)
	}
}

func main() {
	a1, _ = net.Dial("tcp", "127.0.0.1:9900")
	RunPortServer(":8800")
}
